*** Explaining Migration Timing
*** Alisha Holland and Margaret Peters

version 14

************ Observational Data from Secondary Sources 
*** Figure 1: The Puzzle 

*** Left Panel
*** using illegalcrossings.dta
*** Data available at Frontex 
line emed cmed wbalk year, xlab(2008(1)2016) ylab(0(200)1000, nogrid) lcolor (black gray black) lstyle(solid solid dot) legend(lwidth(none) label(1 "E. Mediterranean") label(2 "C. Mediterranean") label(3 "W. Balkan") order(1 2 3) rows(1)) ytitle("Illegal Border Crossings Detected (thousands)") xtitle("Year")graphregion(color(white) lcolor(white)) 
graph export fig1_puzzleleft.tif, width(7200)

*** Right Panel
*** using asylumapps.dta
*** Data available at http://ec.europa.eu/eurostat/web/asylum-and-managed-migration/data/
line syria afghanistan iraq year, xlab(2000(2)2018) ylab(0(100)100, nogrid) lcolor (black gray black ) lstyle(solid solid dot) legend(lwidth(none) label(1 "Syria") label(2 "Afghanistan") label(3 "Iraq") order(1 2 3) rows(1)) ytitle("Asylum Applications (thousands)") xtitle("Year")graphregion(color(white) lcolor(white)) 
graph export fig1_puzzleright.tif, width(7200)


*** Figure 2: The Limited Explanatory Power of Violence in Syria and Iraq
*** Data and figure produced in Excel 

************ Original Survey Data 
*** Analyzed using Stata 14.0



use "holland_peters_explaining_timing_survey.dta", clear

*** Political Knowledge Questions 

*** Meaning of Asylum
gen correctasylum = .
*** For those at permanent residence, this was coded as a single option:
replace correctasylum = 1 if Da40==2
replace correctasylum = 0 if Da40==1|Da40==3|Da40==4
** For those who migrated, this was coded as check multiple so we code the answer as right as long as their answers don't contradict the correct response:
replace correctasylum = 1 if D4_2==1 
replace correctasylum = 0 if D4_3==1 & D4_2!=1
** They are coded as wrong if they also said the peson could stay permanently anywhere
replace correctasylum = 0 if D4_1==1
** They are coded as wrong if they said they didn't know
replace correctasylum = 0 if D4_4==1
label variable correctasylum "Meaning of asylum"

*** Asylum in Gulf
*** Correct answer was no country offers asylum, D5_6==1 or Da41_6==1
gen correctgulf = .
replace correctgulf = 1 if D5_6==1|Da41_6==1
replace correctgulf = 0 if D5_1==1|D5_2==1|D5_3==1|D5_4==1|D5_5==1|Da41_1==1|Da41_2==1|Da41_3==1|Da41_4==1|Da41_5==1
label variable correctgulf "Asylum in Gulf"

*** Resettlement
*** Considered correct if checked Syria only or Syria + Iraq, incorrect if checked Afghanistan or Eritrea
generate correctrelocation = .
replace correctrelocation =1 if D9_1==1
replace correctrelocation =0 if D9_2==1 
replace correctrelocation =1 if D9_2==1 & D9_1==1
replace correctrelocation =0 if D9_3==1
replace correctrelocation =0 if D9_4==1
replace correctrelocation =1 if Da45_1==1
replace correctrelocation =0 if Da45_2==1 
replace correctrelocation =1 if Da45_2==1 & Da45_1==1
replace correctrelocation =0 if Da45_3==1
replace correctrelocation =0 if Da45_4==1
label variable correctrelocation "Resettlement"

*** German Chancellor
generate Merkel = .
replace Merkel = 1 if D8==2|Da44==2
replace Merkel = 0 if D8==1|D8==3|D8==4|Da44==1|Da44==3|Da44==4
label variable Merkel "German Chancellor"

*** Country Accepting Most
** Code as correct for Germany Da42==3 and D6_3==1
recode D6_1-D6_5 (-99=.)
gen correctmost = .
replace correctmost = 1 if Da42==3|D6_3==1
replace correctmost = 0 if Da42==2|Da42==1|Da42==4|Da42==5|D6_1==1|D6_2==1|D6_4==1|D6_5==1
label variable correctmost "Country Accepting Most"

*** Country Accepting Fewest
*** Accept Hungary or UK as the correct asnwer
gen correctleast = .
replace correctleast = 1 if D7==5|D7==1|Da43==5|Da43==1
replace correctleast = 0 if D7==2|D7==3|D7==4|Da43==2|Da43==3|Da43==4 
label variable correctleast "Country Accepting Fewest"

*** Political knowledge index 
generate knowledge = (correctasylum + correctgulf + correctrelocation + Merkel + correctmost + correctleast )/6
label variable knowledge "Mean Knowledge"

*** Recode missing Country  
recode Country (-99=.)

** Table 1: Political Knowledge 
preserve
eststo clear
drop if Country==.
by Country, sort: eststo: quietly estpost summarize correctasylum correctgulf correctrelocation Merkel correctmost correctleast knowledge 
eststo: quietly estpost summarize correctasylum correctgulf correctrelocation Merkel correctmost correctleast knowledge 
esttab using table1knowledge8.tex, cells("mean (fmt(3))") label nodepvar noobs replace
restore

*** Correlates of Political Knowledge 

*** Worse Violence, measure for whether violence deteriorated in the past year
gen worseyear = .
replace worseyear = 1 if A14==1 & AGC== .
replace worseyear = 1 if AGC==1 & A14==.
replace worseyear = 0 if A14!=1 & A14!=. & AGC==.
replace worseyear = 0 if AGC!=1 & AGC!=. & A14==. 
by Country, sort: summarize worseyear
label variable worseyear "Worse Violence"

*** Worse Goods, measure for whether access to range of goods deteriorated in the past year

recode A9a-A9l (-99=.)
recode A5a-A5l (-99=.)

gen wg1 = .
replace wg1 = 1 if A9a==2 & A5a==.
replace wg1 = 0 if A9a!=2 & A9a!=. & A5a==.
replace wg1 = 1 if A5a==2 & A9a==.
replace wg1 = 0 if A5a!=2 & A5a!=. & A9a==.

gen wg2 = .
replace wg2 = 1 if A9b==2 & A5b==.
replace wg2 = 0 if A9b!=2 & A9b!=. & A5b==.
replace wg2 = 1 if A5b==2 & A9b==.
replace wg2 = 0 if A5b!=2 & A5b!=. & A9b==.

gen wg3 = .
replace wg3 = 1 if A9c==2 & A5c==.
replace wg3 = 0 if A9c!=2 & A9c!=. & A5c==.
replace wg3 = 1 if A5c==2 & A9c==.
replace wg3 = 0 if A5c!=2 & A5c!=. & A9c==.

gen wg4 = .
replace wg4 = 1 if A9d==2 & A5d==.
replace wg4 = 0 if A9d!=2 & A9d!=. & A5d==.
replace wg4 = 1 if A5d==2 & A9d==.
replace wg4 = 0 if A5d!=2 & A5d!=. & A9d==.

gen wg5 = .
replace wg5 = 1 if A9e==2 & A5e==.
replace wg5 = 0 if A9e!=2 & A9e!=. & A5e==.
replace wg5 = 1 if A5e==2 & A9e==.
replace wg5 = 0 if A5e!=2 & A5e!=. & A9e==.

gen wg6 = .
replace wg6 = 1 if A9f==2 & A5f==.
replace wg6 = 0 if A9f!=2 & A9f!=. & A5f==.
replace wg6 = 1 if A5f==2 & A9f==.
replace wg6 = 0 if A5f!=2 & A5f!=. & A9f==.

gen wg7 = .
replace wg7 = 1 if A9g==2 & A5g==.
replace wg7 = 0 if A9g!=2 & A9g!=. & A5g==.
replace wg7 = 1 if A5g==2 & A9g==.
replace wg7 = 0 if A5g!=2 & A5g!=. & A9g==.

gen wg8 = .
replace wg8 = 1 if A9h==2 & A5h==.
replace wg8 = 0 if A9h!=2 & A9h!=. & A5h==.
replace wg8 = 1 if A5h==2 & A9h==.
replace wg8 = 0 if A5h!=2 & A5h!=. & A9h==.

gen wg9 = .
replace wg9 = 1 if A9i==2 & A5i==.
replace wg9 = 0 if A9i!=2 & A9i!=. & A5i==.
replace wg9 = 1 if A5i==2 & A9i==.
replace wg9 = 0 if A5i!=2 & A5i!=. & A9i==.

gen wg10 = .
replace wg10 = 1 if A9j==2 & A5j==.
replace wg10 = 0 if A9j!=2 & A9j!=. & A5j==.
replace wg10 = 1 if A5j==2 & A9j==.
replace wg10 = 0 if A5j!=2 & A5j!=. & A9j==.

gen wg11 = .
replace wg11 = 1 if A9k==2 & A5k==.
replace wg11 = 0 if A9k!=2 & A9k!=. & A5k==.
replace wg11 = 1 if A5k==2 & A9k==.
replace wg11 = 0 if A5k!=2 & A5k!=. & A9k==.

gen wg12 = .
replace wg12 = 1 if A9l==2 & A5l==.
replace wg12 = 0 if A9l!=2 & A9l!=. & A5l==.
replace wg12 = 1 if A5l==2 & A9l==.
replace wg12 = 0 if A5l!=2 & A5l!=. & A9l==.

gen worsegoods = .
replace worsegoods = (wg1 + wg2 + wg3 + wg4 + wg5 + wg6 + wg8 + wg9 + wg10 + wg11 + wg12)/11
label variable worsegoods "Worse Goods" 

*** Camps
gen camps = .
replace camps = 1 if C2abc_3_TEXT>0
replace camps = 0 if C2abc_3_TEXT==.
label variable camps "Camps" 

*** Wealth
*** PCA based on current assets for entire sample so pais =1, replace pais with Country if doing wealth by country 

generate pais=.
replace pais=1 if Country==1 & Country!=.
replace pais=2 if Country==2 & Country!=.
replace pais=3 if Country==4 & Country!=.
replace pais=4 if Country==5 & Country!=.


sort pais
by pais: pca K14_1  K14_2 K14_3 K14_4  K14_5 K14_6 K14_7 K14_8 K14_9 K14_10 K14_11 K14_12 K14_13
predict consumption, score
gen pconsump= .
levelsof pais, local(temppais)
foreach i in `temppais' {
xtile consump_temp=consumption if pais==`i', nq(10)
replace pconsump = consump_temp if missing(pconsump)
drop consump_temp
}

generate wealth = .
replace wealth = (pconsump -1)/9
label variable wealth "Wealth" 

*** Education rescaled from 0 to 1
recode K8 (-99=.)
gen education = (K8-1)/6
label variable education "Education"

*** Female, coded with female as "1"
generate gender = K1
recode gender (1=0)(0=1)
label variable gender "Female"

*** Religiosity
*** Coding so more religious people get higher values and then rescaling 0 to 1
*** Prayer: Do you pray daily?
recode ACH (-99=.)(5=1)(4=2)(3=3)(2=4)(1=5)
*** scale of labels used on the following questions
label define religiosityl 1 "Never" 2 "Rarely" 3 "Sometimes" 4 "Most of the time" 5 "Always"
label values ACH religiosityl

*** Services: Do you attend Friday prayer or Sunday services?
recode ACI (-99=.)(5=1)(4=2)(3=3)(2=4)(1=5)
label values ACI religiosityl 

***Quran: Do you listen to or read the Quran or Bible?
recode ACJ (-99=.)(5=1)(4=2)(3=3)(2=4)(1=5)
label values ACJ religiosityl 

** Dress: What is the appropriate dress for women?  
recode ACK (-99=.)
label values ACK religionw

*** Index of religiosity, rescaled from 0 to 1
generate religiosity = ((ACH + ACI + ACJ + ACK)-4)/16
label variable religiosity "Religiosity"

*** News: How often do you pay attention to the news now?
*** rescale so that higher values are higher numbers 
generate newsnow = .
replace newsnow = 0 if B10==5 | Ba11==5
replace newsnow =1 if B10==4 |Ba11==4
replace newsnow =2 if B10==3 |Ba11==3
replace newsnow =3 if B10==2 |Ba11==2
replace newsnow =4 if B10==1 |Ba11==1
label define newsf 0 "Never" 1 "Rarely" 2 "A few times a month" 3 "A few times a week" 4 "Daily" 
label values newsnow newsf
generate newsnowsc = newsnow/4
label variable newsnowsc "News"

*** Family
*** Coding error means this only is available for part of the sample
recode C16 Ca33 (-99=.)
generate family = .
replace family = 1 if C16==1|C16==2|Ca33==1|Ca33==2
replace family = 0 if C16==3|Ca33==3
label variable family "Family"

tab Country, gen(country_interview)
renvars country_interview1 country_interview2 country_interview3 country_interview4  \  Turkey Jordan Syria Iraq 

*** If renvars command doesn't work in your stata version, dummy variables for each individual country 
***rename country_interview1 Turkey
***rename country_interview2 Jordan
***rename country_interview3 Syria
***rename country_interview4 Iraq 
***label variable Turkey "Turkey"
***label variable Jordan "Jordan"
***label variable Syria "Syria"
***label variable Iraq "Iraq"

*** Figure 4: Correlates of Political Knowledge
preserve
reg knowledge worseyear worsegoods Turkey Syria Iraq camps wealth education gender, robust
estimates store D
reg knowledge worseyear worsegoods Turkey Syria Iraq camps wealth education gender religiosity newsnowsc, robust
estimates store E
reg knowledge worseyear worsegoods Turkey camps wealth education gender religiosity family, robust
estimates store F
coefplot (D, label("Model 1, N=1,098") mcolor(black) msymbol(smcircle)) (E, label("Model 2, N=1,904") pstyle(p4) msymbol(smtriangle)) (F, label("Model 3, N=682")pstyle(p5) msymbol(smsquare)), drop(_cons) xline(0) xtitle("Coefficient Estimates and 95% Confidence Intervals") scheme(s1mono) graphregion(fcolor(white)) plotregion(fcolor(white)) bgcolor(white) grid(none) legend(rows(1))
graph export fig4_politicalknowledge.tif, width(7200) replace
restore

*** Explanations for secondary decisions to reach Europe
**** In terms of their \emph{primary} migration decisions, most Syrians and Iraqis said they moved following substantial violence and in haste.\footnote{ About half of our survey sample said they had only days to gather their belongings and 30 percent had only hours.}  But explanations for secondary decisions to reach Europe centered on the policy environment: the most common explanation was that ``EU countries were willing to accept more migrants'' (54 percent).  Far fewer respondents supported herd or social network interpretations that ``it became easier to live in Europe once friends and family had left'' (13 percent).

*** only 68 percent of Iraqis and 41 percent of Jordanians could correctly name their own foreign minister \citep{ArabBarometer}. 





**************** Experiment
version 13
****Different treatment comparison groups
gen infoall_control=.
replace infoall_control=0 if wavetreatment==0
replace infoall_control=1 if wavetreatment>=1
replace infoall_control=. if wavetreatment==.

gen info_control=.
replace info_control=0 if wavetreatment==0
replace info_control=1 if wavetreatment==1

gen symp_control=.
replace symp_control=0 if wavetreatment==0
replace symp_control=1 if wavetreatment==2

gen opening_control=.
replace opening_control=0 if wavetreatment==0
replace opening_control=1 if wavetreatment==3

gen hostile_control=.
replace hostile_control=0 if wavetreatment==0
replace hostile_control=1 if wavetreatment==4


gen symp_info=.
replace symp_info=0 if wavetreatment==1
replace symp_info=1 if wavetreatment==2

gen opening_info=.
replace opening_info=0 if wavetreatment==1
replace opening_info=1 if wavetreatment==3

gen hostile_info=.
replace hostile_info=0 if wavetreatment==1
replace hostile_info=1 if wavetreatment==4


gen opening_hostile=.
replace opening_hostile=0 if wavetreatment==4
replace opening_hostile=1 if wavetreatment==3

gen opening_symp=.
replace opening_symp=0 if wavetreatment==2
replace opening_symp=1 if wavetreatment==3

gen symp_hostile=.
replace symp_hostile=0 if wavetreatment==4
replace symp_hostile=1 if wavetreatment==2



*** Knowledge index

*** Political knowledge index

summarize knowledge, detail
egen know_p33=pctile(knowledge), p(33)
egen know_p67=pctile(knowledge), p(67)

gen know_index=.
replace know_index=0 if knowledge<=know_p33
replace know_index=1 if knowledge>know_p33
replace know_index=. if knowledge==.

*****Clean questions & create indices

*Legal and policy treatment

recode F3 (-99=.)
recode F4 (-99=.)
recode F5 (-99=.)
recode F7 (-99=.)
recode F14 (-99=.)	


recode F3 (2=0)
recode F4 (2=0) 
recode F5 (2=0)
recode F7 (2=0)
recode F14 (2=0)

summarize F3 F4 F5 F7 F14

egen misslegal=rowmiss(F3 F4 F5 F7 F14)

gen legal=.
replace legal=( F3+F4+F5+F7+F14)/5 if misslegal==0 /* higher values means better treatment*/


*Border enforcement
recode F6 (-99=.)
recode F8 (-99=.)
recode F6 (1=0)
recode F6 (2=1)
recode F8 (1=0)
recode F8 (2=1)
recode F15 (-99=.)	
recode F15 (1=0)
recode F15 (2=1)

summarize F6 F8 F15
egen missborder=rowmiss(F6 F8 F15)

gen borderen=.
replace borderen=(F6+F8+F15)/3 if missborder==0 /*higher values means less enforcement*/


*danger in journey/ smugglers

recode F9 (-99=.)
recode F9 (2=0)


gen go_smug=.
replace go_smug=1 if F10==1
replace go_smug=0 if F10==2| F10==3 | F10==4


gen go_smug_friend=.
replace go_smug_friend=1 if F16==1
replace go_smug_friend=0 if F16==2 | F16==3

gen go_smug_friend6mn=.
replace go_smug_friend6mn=1 if F17==1
replace go_smug_friend6mn=0 if F17==2 | F17==3

gen danger_journ=.
replace danger_journ=1 if F18==1
replace danger_journ=0 if F18==2 | F18==3


*Likelihood of being in Europe soon
recode F11 (-99=.)
recode F12 (-99=.)
recode F13 (-99=.)

recode F11 (2=0)
recode F12 (2=0)
recode F13 (2=0)

summarize F11 F12 F13
egen misslikeli=rowmiss(F11 F12 F13)

gen eusoon=.
replace eusoon=(F11+F12+F13)/3 /*higher values means be there soon*/


***situation at home 
recode F19 (-99=.)
recode F23 (-99=.)

gen violence=.
replace violence=1 if F19==3 | F23==3
replace violence=0 if F19==1 | F19==2 | F23==1 |F23==2

gen goods=.
replace goods=1 if F20==3 | F24==3
replace goods=0 if F20==1 | F20==2 | F24==1 |F24==2

gen turkey=.
replace turkey=0 if F21==1 | F21==2
replace turkey=1 if F21==3
replace turkey=0 if F25==1 | F25==2
replace turkey=1 if F25==3


gen trust=.
replace trust=1 if F22==1
replace  trust=0 if F22>1 & F22!=.
replace trust=1 if F26==1
replace  trust=0 if F26>1 & F26!=.

summarize violence goods turkey trust
egen misshome=rowmiss(violence goods turkey trust)

gen home=.
replace home=(violence+goods+turkey+trust)/4 /*higher values means things are getting worse at home*/


***know about Europe
recode F27 (-99=.)
gen knowanything_europe=.
replace knowanything_europe=0 if F27==3
replace knowanything_europe=1 if F27==1 | F23==2

recode F28 (-99=.)
recode F28 (3=.)
recode F28 (2=0)


recode F29 (-99=.)
recode F29 (3=.)
recode F29 (2=0)

recode F30 (-99=.)
recode F30 (1=0)
recode F30 (2=1)

summarize knowanything_europe F28 F29 F30
egen missknow=rowmiss(knowanything_europe F28 F29 F30)

gen knoweu=.
replace knoweu=(knowanything_europe+F28+F29+F30)/4 /* higher values means you know more/ get job/ less discrimination */


*factor analysis & Appendix Table A10


factor F3 F4 F5 F6 F7 F8 F9 go_smug F11 F12 F13 F14 F15 go_smug_friend go_smug_friend6mn ////
danger_journ violence goods turkey trust knowanything_europe F28 F29 F30, pcf
rotate
predict condhometrans smugglers staywork beeusoon friends borderenforce trust2




*******************************************
**T-tests individual questions

set scheme plotplain


set more off
**Simple & Bayesian herd
preserve
foreach var in violence goods turkey trust F6 F8 F15  F11 F12 F13 F3 F4 F5 F7 F14 {
foreach cond in info_control symp_control  {
	ttest `var' if know_index==0, by(`cond')
	matrix ttesth_`var'_`cond'= (r(mu_1), r(sd_1), r(N_1), r(mu_2), r(sd_2), r(N_2), r(se), r(p), r(df_t) )
	matrix rownames ttesth_`var'_`cond'= `var'_`cond'
	matrix colnames ttesth_`var'_`cond'= mean1 se1 n1 mean2 se2 n2 diffse pval df
	matsave ttesth_`var'_`cond', replace saving
		}
}
restore

set more off
**Opening
preserve
foreach var in  F6 F8 F15  F11 F12 F13 F3 F4 F5 F7 F14 {
foreach cond in  opening_control   {
	ttest `var' if know_index==0, by(`cond')
	matrix ttesto_`var'_`cond'= (r(mu_1), r(sd_1), r(N_1), r(mu_2), r(sd_2), r(N_2), r(se), r(p), r(df_t) )
	matrix rownames ttesto_`var'_`cond'= `var'_`cond'
	matrix colnames ttesto_`var'_`cond'= mean1 se1 n1 mean2 se2 n2 diffse pval df
	matsave ttesto_`var'_`cond', replace  saving
	}
}
restore

set more off
**Hostile
preserve
foreach var in  F6 F8 F15  F11 F12 F13 F3 F4 F5 F7 F14 {
foreach cond in    hostile_control  {
	ttest `var' if know_index==0, by(`cond')
	matrix ttestho_`var'_`cond'= (r(mu_1), r(sd_1), r(N_1), r(mu_2), r(sd_2), r(N_2), r(se), r(p), r(df_t) )
	matrix rownames ttestho_`var'_`cond'= `var'_`cond'
	matrix colnames ttestho_`var'_`cond'= mean1 se1 n1 mean2 se2 n2 diffse pval df
	matsave ttestho_`var'_`cond', replace saving
	}
}

restore

******Figure 5

preserve

	use "ttesth_violence_symp_control", clear
	append using "ttesth_goods_symp_control"
	append using "ttesth_turkey_symp_control"
	append using "ttesth_trust_symp_control"
	append using "ttesth_F6_symp_control"
	append using "ttesth_F8_symp_control"
	append using "ttesth_F15_symp_control"
	append using "ttesth_F11_symp_control"
	append using "ttesth_F12_symp_control"
	append using "ttesth_F13_symp_control"
	append using "ttesth_F3_symp_control"
	append using "ttesth_F4_symp_control"
	append using "ttesth_F5_symp_control"
	append using "ttesth_F7_symp_control"
	append using "ttesth_F14_symp_control"
	append using "ttesth_violence_info_control"
	append using "ttesth_goods_info_control"
	append using "ttesth_turkey_info_control"
	append using "ttesth_trust_info_control"
	append using "ttesth_F6_info_control"
	append using "ttesth_F8_info_control"
	append using "ttesth_F15_info_control"
	append using "ttesth_F11_info_control"
	append using "ttesth_F12_info_control"
	append using "ttesth_F13_info_control"
	append using "ttesth_F3_info_control"
	append using "ttesth_F4_info_control"
	append using "ttesth_F5_info_control"
	append using "ttesth_F7_info_control"
	append using "ttesth_F14_info_control"
	
	append using "ttesto_F6_opening_control"
	append using "ttesto_F8_opening_control"
	append using "ttesto_F15_opening_control"
	append using "ttesto_F11_opening_control"
	append using "ttesto_F12_opening_control"
	append using "ttesto_F13_opening_control"
	append using "ttesto_F3_opening_control"
	append using "ttesto_F4_opening_control"
	append using "ttesto_F5_opening_control"
	append using "ttesto_F7_opening_control"
	append using "ttesto_F14_opening_control"

	append using "ttestho_F6_hostile_control"
	append using "ttestho_F8_hostile_control"
	append using "ttestho_F15_hostile_control"
	append using "ttestho_F11_hostile_control"
	append using "ttestho_F12_hostile_control"
	append using "ttestho_F13_hostile_control"
	append using "ttestho_F3_hostile_control"
	append using "ttestho_F4_hostile_control"
	append using "ttestho_F5_hostile_control"
	append using "ttestho_F7_hostile_control"
	append using "ttestho_F14_hostile_control"
	
	renvars _rowname mean1 se1 n1 mean2 se2 n2 \ t_test mu1 sd1 num1 mu2 sd2 num2

	gen diff=mu2-mu1 /*difference in means*/


	gen lb90=diff-1.645*diffse /*90% CI*/
	replace lb90=diff-2.132*diffse if df==4
	replace lb90=diff-1.697*diffse if df>=30 & df<40
	replace lb90=diff-1.684*diffse if df>=40 & df<60
	replace lb90=diff-1.658*diffse if df>=60 & df<120

	gen ub90=diff+1.645*diffse /*90% CI*/
	replace ub90=diff+2.132*diffse if df==4
	replace ub90=diff+1.697*diffse if df>=30 & df<40
	replace ub90=diff+1.684*diffse if df>=40 & df<60
	replace ub90=diff+1.658*diffse if df>=60 & df<120

	gen lb95=diff-1.96*diffse /*95% CI*/
	replace lb95=diff-2.776*diffse if df==4
	replace lb95=diff-2.042*diffse if df>=30 & df<40
	replace lb95=diff-2.021*diffse if df>=40 & df<60
	replace lb95=diff-2*diffse if df>=60 & df<120

	gen ub95=diff+1.96*diffse /*95% CI*/
	replace ub95=diff+2.776*diffse if df==4
	replace ub95=diff+2.042*diffse if df>=30 & df<40
	replace ub95=diff+2.021*diffse if df>=40 & df<60
	replace ub95=diff+2*diffse if df>=60 & df<120


	split t_test, p("_")
	renvars t_test1 t_test2 t_test3  \ variable group2 group1  

	sort variable
	encode variable, gen(vars) 
		/*1=F11 2= F12 3=F13 4=F14 5=F15 6=F3 7=F4 8=F5 9=F6 10=F7 11=F8 12=goods 13=trust 14=Turkey 15=violence */
	sort group2
	encode group2, gen(treat2)
		/* 1=hostile 2=info 3=opening  4=symp */	
		
	sort group1 
	encode group1, gen(treat1) /* 1=Control */

	gen simple=0
	replace simple=1 if treat2==2 & vars==1
	replace simple=1 if treat2==2 & vars==2
	replace simple=1 if treat2==2 & vars==3
		replace simple=1 if treat2==4 & vars==1
	replace simple=1 if treat2==4 & vars==2
	replace simple=1 if treat2==4 & vars==3

	tab variable


	sort    treat2 treat1 vars


	mkmat pval diff lb90 ub90 lb95 ub95 vars treat2 treat1 if treat2==1, matrix(hostile)
	matrix list hostile
	matrix rown hostile = f11 f12 f13 f14 f15 f3 f4 f5 f6 f7 f8 

	mkmat pval diff lb90 ub90 lb95 ub95 vars treat2 treat1 if treat2==2, matrix(info)
	matrix list info
	matrix rown info = f11 f12 f13 f14 f15 f3 f4 f5 f6 f7 f8 good trus tur vio

	mkmat pval diff lb90 ub90 lb95 ub95 vars treat2 treat1 if treat2==3, matrix(open)
	matrix list open
	matrix rown open = f11 f12 f13 f14 f15 f3 f4 f5 f6 f7 f8


	mkmat pval diff lb90 ub90 lb95 ub95 vars treat2 treat1 if treat2==2 & simple==1, matrix(siminfo)
	matrix list siminfo
	matrix rown siminfo = f11 f12 f13

	mkmat pval diff lb90 ub90 lb95 ub95 vars treat2 treat1 if treat2==4 & simple==1, matrix(simsymp)
	matrix list simsymp
	matrix rown simsymp = f11 f12 f13

	mkmat pval diff lb90 ub90 lb95 ub95 vars treat2 treat1 if treat2==4, matrix(symp)
	matrix list symp
	matrix rown symp = f11 f12 f13 f14 f15 f3 f4 f5 f6 f7 f8 good trus tur vio


	coefplot (matrix(siminfo[,2]), ci( (siminfo[,5] siminfo[,6]) (siminfo[,3] siminfo[,4])) msymbol(O) label(Size))  ////
		|| ,  xline(0)    ////
			coeflabels(f11="EU 1 month (+)" f12="EU 3 months (+)" f13="EU 6 months (+)", labs(small))  ////
			order(f11 f12 f13) ////
			headings( f11="Timing of Migration", labs(medsmall)) note("NPC p-value: 0.246 (size)") title("Simple Herd")

	gr export fig5_1.pdf, as(pdf) replace
	gr export fig5_1.tif, width(7200) replace



	coefplot (matrix(info[,2]), ci( (info[,5] info[,6]) (info[,3] info[,4])) msymbol(O) label(Size)) ////
	(matrix(symp[,2]), ci( (symp[,5] symp[,6]) (symp[,3] symp[,4])) msymbol(D) label(Sympathetic))  /////
		|| ,  xline(0)   legend(row(1) size(vsmall) pos(6)) ////
				coeflabels(f11="EU 1 month (+)" f12="EU 3 months (+)" f13="EU 6 months (+)"  ////
			f14="Asylum next year (+)" f15="Return to Turkey (+)" f3="Stay permanently (+)" f4="Stay thru conflict (+)" ////
			f5="Bring family (+)" f6="Work permit (+)" ////
			f7="Deportation (+)"  f8="Turn back (+)" good="Goods Access (+)" trus="Trust (+)" tur="Sit. in Turkey (+)" vio="Violence (+)", labs(small)) ////
			order(f11 f12 f13 f3 f4 f5 f6 f14 f7 f8 f15 vio good tur trus) ////
			headings(f7="Border enforcement" f11="Timing of Migration" f3="Legal/ Policy" vio="Conditions at home", labs(medsmall)) ////
			note("NPC p-value: 0.115 (size), 0.158 (sympathetic), 0.093 (both)") title("Bayesian Herd")

	gr export fig5_2.pdf, as(pdf) replace
	gr export fig5_2.tif, width(7200) replace
	
	coefplot  (matrix(open[,2]), ci( (open[,5] open[,6]) (open[,3] open[,4])) msymbol(T) label(Open) )  /////
	,  xline(0)  norecycle  ////
			coeflabels(f11="EU 1 month (+)" f12="EU 3 months (+)" f13="EU 6 months (+)"  ////
			f14="Asylum next year (+)" f15="Return to Turkey (+)" f3="Stay permanently (+)" f4="Stay thru conflict (+)" ////
			f5="Bring family (+)" f6="Work permit (+)" ////
			f7="Deportation (+)"  f8="Turn back (+)" good="Goods Access (+)" trus="Trust (+)" tur="Sit. in Turkey (+)" vio="Violence (+)", labs(small)) ////
			order(f11 f12 f13 f3 f4 f5 f6 f14 f7 f8 f15 vio good tur trus) ////
			headings(f7="Border enforcement" f11="Timing of Migration" f3="Legal/ Policy" vio="Conditions at home", labs(medsmall)) ////
			note("NPC p-value: 0.005 (opening)") title("Political Opportunity")

	gr export fig5_3.pdf, as(pdf) replace
	gr export fig5_3.tif, width(7200) replace
	
	coefplot  (matrix(hostile[,2]), ci( (hostile[,5] hostile[,6]) (hostile[,3] hostile[,4])) msymbol (S) label(Hostile))  /////
	,  xline(0)  ////
		coeflabels(f11="EU 1 month (+)" f12="EU 3 months (+)" f13="EU 6 months (+)"  ////
			f14="Asylum next year (-)" f15="Return to Turkey (-)" f3="Stay permanently (-)" f4="Stay thru conflict (-)" ////
			f5="Bring family (-)" f6="Work permit (-)" ////
			f7="Deportation (-)"  f8="Turn back (-)" good="Goods Access (+)" trus="Trust (+)" tur="Sit. in Turkey (+)" vio="Violence (+)", labs(small)) ////
			order(f11 f12 f13 f3 f4 f5 f6 f14 f7 f8 f15 vio good tur trus) ////
			headings(f7="Border enforcement" f11="Timing of Migration" f3="Legal/ Policy" vio="Conditions at home", labs(medsmall)) ////
			note("NPC p-value: 0.790 (hostile)") title("Political Closure")

	gr export fig5_4.pdf, as(pdf) replace
	gr export fig5_4.tif, width(7200) replace
	
restore


********Output data to R for NPC tests
preserve
keep respond_id          know_index          info_control        symp_control       ////
	opening_control     hostile_control     F3                  F4        ////         
	F5                  F7                  F14                 F6       ////          
	F8                  F15                 F9                  go_smug  ////          
	go_smug_friend      go_smug_friend6mn   danger_journ        F11      ////          
	F12                 F13                 violence            goods    ////          
	turkey              trust               knowanything_europe F28      ////          
	F29                 F30                 legal               borderen ////          
	danger              eusoon              home                knoweu   ////          
	condhometrans       smugglers           staywork            beeusoon ////          
	friends             borderenforce       trust2              

export delimited using "waves_for_npc_replication", nolabel replace
restore



preserve
	keep violence goods turkey trust F6 F8 F15 F11 F12 F13 F3 F4 F5 F7 F14 info_control symp_control respond_id know_index
	keep if know_index==0

	gen bayestreatment=.
	replace bayestreatment=1 if info_control==1
	replace bayestreatment=1 if symp_control==1
	replace bayestreatment=0 if info_control==0 & symp_control==0
	drop if bayestreatment==.


	foreach var in violence goods turkey trust F6 F8 F15 F11 F12 F13 F3 F4 F5 F7 F14 {
		gen `var'_1=`var' if info_control==1 | info_control==0
		gen `var'_2=`var' if symp_control==1 | symp_control==0
	} 

	keep respond_id bayestreatment  violence_1 violence_2 goods_1 goods_2 turkey_1 turkey_2 trust_1 trust_2 F6_1 ////
	F6_2 F8_1 F8_2 F15_1 F15_2 F11_1 F11_2 F12_1 F12_2 F13_1 F13_2 F3_1 F3_2 F4_1 F4_2 F5_1 F5_2 F7_1 F7_2 F14_1 F14_2

	export delimited using "waves_data_npc_bayes_combined", nolabel replace
restore



************ Google Search Data 
*** Produced in Stata 14.0
version 14 
*** Figure 6: Google Search Trends 
*** Left panel
use asylumsyria.dta, clear
gen date2=date(week,"MDY")
tsset date2
graph twoway tsline asylum germany britain, tlabel(19231 "9/12" 19910 "Merkel 6/14" 20337 "Merkel 8/15" 20624 "Brexit 6/16" 21051 "9/17") lcolor (black gray black) lstyle(solid solid dot)  xtitle("Time") ytitle("Relative Interest in Turkey")ylab(0(20)100, nogrid) graphregion(fcolor(white)) plotregion(fcolor(white)) bgcolor(white)legend(rows(1))
graph export fig6_asylumleft.tif, width(7200)

*** Right panel
use asylumturkey.dta, clear
gen date2=date(week,"MDY")
tsset date2
graph twoway tsline asylum germany britain, tlabel(19231 "9/12" 19910 "Merkel 6/14" 20337 "Merkel 8/15" 20624 "Brexit 6/16" 21051 "9/17") lcolor (black gray black) lstyle(solid solid dot) xtitle("Time") ytitle("Relative Interest in Syria")ylab(0(20)100, nogrid) graphregion(fcolor(white)) plotregion(fcolor(white)) bgcolor(white)legend(rows(1)) scheme(s2mono)
graph export fig6_asylumright.tif, width(7200)


 

************ Appendix 
version 14
*** Appendix A
*use "holland_peters_explaining_timing_survey.dta", clear

*** Ability to Save: reverse the coding so higher indicates wealthier (can't cover expenses 0, able to save 1)
generate wealthcap=.
replace wealthcap =A10 if Country==1|Country==2
replace wealthcap=AFM if Country==4|Country==5
replace wealthcap=wealthcap/3
label variable wealthcap "Wealth"

** Table A1.  OLS Regression of Knowledge Index with Alternative Wealth Measures
eststo clear
eststo, title("Model 1"): quietly reg knowledge worseyear worsegoods wealth education gender, robust
eststo, title("Model 1"): quietly reg knowledge worseyear worsegoods wealth education gender religiosity newsnowsc, robust
eststo, title("Model 1"): quietly reg knowledge worseyear worsegoods wealth education gender religiosity family  , robust

eststo, title("Model 1"): quietly reg knowledge worseyear worsegoods wealthcap education gender, robust
eststo, title("Model 1"): quietly reg knowledge worseyear worsegoods wealthcap education gender religiosity newsnowsc, robust
eststo, title("Model 1"): quietly reg knowledge worseyear worsegoods wealthcap education gender religiosity family  , robust
esttab using knowledgeapp.tex, cells(b(star fmt(3)) se(par fmt(2))) obslast  stats(r2, fmt(3) label(R-sqr)) keep(worseyear worsegoods family wealth wealthcap education gender religiosity newsnowsc) label title("OLS Regression of Knowledge Index with Alternative Wealth Measures\label{impactiv}")  replace

*** Table A2. OLS Regression of Knowledge Index with Alternative Violence Measures

gen worseweek = .
replace worseweek = 1 if A12==1 & AGA == .
replace worseweek = 1 if AGA==1 & A12==.
replace worseweek = 0 if A12!=1 & A12!=. & AGA==.
replace worseweek = 0 if AGA!=1 & AGA!=. & A12==.

gen worsemonth = .
replace worsemonth = 1 if A13==1 & AGB== .
replace worsemonth = 1 if AGB==1 & A13==.
replace worsemonth = 0 if A13!=1 & A13!=. & AGB==.
replace worsemonth = 0 if AGB!=1 & AGB!=. & A13==.

*** Political violence index
egen violence_tot=rowtotal(A11_1 A11_2 A11_3 A11_4 A11_5 A11_6 A11_7 A11_8 A11_9 A11_10 A11_11 A11_12)
replace violence_tot=. if violence_tot==-1188 | violence_tot==0
egen violence_tot2=rowtotal(A7_1 A7_2 A7_3 A7_4 A7_5 A7_6 A7_7 A7_8 A7_9 A7_10 A7_11 A7_12)
replace violence_tot2=. if  violence_tot2==0

gen violence_index=.
replace violence_index=violence_tot/12
replace violence_index=violence_tot2/12 if violence_tot2!=.

label variable violence_index "Violence Index"
label variable worseweek "Worse Week"
label variable worsemonth "Worse Month"

eststo clear
eststo, title("Model 1"): quietly reg knowledge worseweek worsegoods wealth education gender, robust
eststo, title("Model 1"): quietly reg knowledge worseweek worsegoods wealth education gender religiosity newsnowsc, robust
eststo, title("Model 1"): quietly reg knowledge worseweek worsegoods wealth education gender religiosity family  , robust

eststo, title("Model 1"): quietly reg knowledge worsemonth worsegoods wealth education gender, robust
eststo, title("Model 1"): quietly reg knowledge worsemonth worsegoods wealth education gender religiosity newsnowsc, robust
eststo, title("Model 1"): quietly reg knowledge worsemonth worsegoods wealth education gender religiosity family  , robust

eststo, title("Model 1"): quietly reg knowledge worsegoods violence_index wealth education gender, robust
eststo, title("Model 1"): quietly reg knowledge worsegoods violence_index wealth education gender religiosity newsnowsc, robust
eststo, title("Model 1"): quietly reg knowledge worsegoods violence_index wealth education gender religiosity family  , robust

esttab using altviolence2.tex, cells(b(star fmt(3)) se(par fmt(2))) obslast  stats(r2, fmt(3) label(R-sqr)) keep(worseweek worsemonth  violence_index worsegoods family  wealth education gender religiosity newsnowsc) label title("OLS Regression of Knowledge Index with Alternative Violence Measures\label{impactiv}")  replace



*** Table A3. OLS Regression of Reported Violence and Deprivation on Beliefs about Who Sent Survey Enumerator

*** Code open response about who sent enumerators (L1) into broad categories 
*** "1" if mentioned universities, research, or our survey firm (Proximity) 
*** "0" if didn't know, thought foreign agent, government, UN 

generate enumeratorsent = 0
replace enumeratorsent = 1 if L1=="Proximity"
replace enumeratorsent = 1 if L1=="Proximity and British universities"
replace enumeratorsent = 1 if L1=="A British university and an American university via Proximity"
replace enumeratorsent = 1 if L1=="a research organization"
replace enumeratorsent = 1 if L1=="a research institution"
replace enumeratorsent = 1 if L1=="a research institute"
replace enumeratorsent = 1 if L1=="a research company"
replace enumeratorsent = 1 if L1=="A university doing a study"
replace enumeratorsent = 1 if L1=="American researchers from a university" 
replace enumeratorsent = 1 if L1=="American studies" 
replace enumeratorsent = 1 if L1=="American universities" 
replace enumeratorsent = 1 if L1=="American university for research" 
replace enumeratorsent = 1 if L1=="American university research" 
replace enumeratorsent = 1 if L1=="British university"
replace enumeratorsent = 1 if L1=="Committee of research and studies" 
replace enumeratorsent = 1 if L1=="Doctoral dissertation" 
replace enumeratorsent = 1 if L1=="European universities" 
replace enumeratorsent = 1 if L1=="Harvard"
replace enumeratorsent = 1 if L1=="Harvard University"
replace enumeratorsent = 1 if L1=="Harvard a university" 
replace enumeratorsent = 1 if L1=="Harvard and Yale"
replace enumeratorsent = 1 if L1=="Harvard and Yale academics"
replace enumeratorsent = 1 if L1=="Harvard and a research organization"
replace enumeratorsent = 1 if L1=="Harvard doing a survey on migration"
replace enumeratorsent = 1 if L1=="Harvard university"
replace enumeratorsent = 1 if L1=="Harvard, according to what you told me"
replace enumeratorsent = 1 if L1=="Proximity and British university"
replace enumeratorsent = 1 if L1=="Proximity in Turkey"
replace enumeratorsent = 1 if L1=="Proximity with research universities"
replace enumeratorsent = 1 if L1=="Proximity working with academic universities"
replace enumeratorsent = 1 if L1=="Proximity, Harvard and Yale"
replace enumeratorsent = 1 if L1=="Proximity, Harvard, and Yale"
replace enumeratorsent = 1 if L1=="Researchers from Harvard and Yale"
replace enumeratorsent = 1 if L1=="SAP University and Harvard"
replace enumeratorsent = 1 if L1=="University studies"
replace enumeratorsent = 1 if L1=="Yale"
replace enumeratorsent = 1 if L1=="Yale and Harvard"
replace enumeratorsent = 1 if L1=="You told me Harvard"
replace enumeratorsent = 1 if L1=="You told us Harvard"
replace enumeratorsent = 1 if L1=="a British university"
replace enumeratorsent = 1 if L1=="a European university"
replace enumeratorsent = 1 if L1=="a Western university"
replace enumeratorsent = 1 if L1=="a center"
replace enumeratorsent = 1 if L1=="a center for humanitarian research"
replace enumeratorsent = 1 if L1=="a committee"
replace enumeratorsent = 1 if L1=="a competent authority of studies"
replace enumeratorsent = 1 if L1=="a competent university"
replace enumeratorsent = 1 if L1=="a foreign university"
replace enumeratorsent = 1 if L1=="a research team"
replace enumeratorsent = 1 if L1=="a research university"
replace enumeratorsent = 1 if L1=="Qualtrics"
replace enumeratorsent = 1 if L1=="a researcher"
replace enumeratorsent = 1 if L1=="a reseasrch university"
replace enumeratorsent = 1 if L1=="a student"
replace enumeratorsent = 1 if L1=="a suitable person"
replace enumeratorsent = 1 if L1=="a survey study"
replace enumeratorsent = 1 if L1=="a university"
replace enumeratorsent = 1 if L1=="a university Western?"
replace enumeratorsent = 1 if L1=="a university doing a study"
replace enumeratorsent = 1 if L1=="a university doing studies"
replace enumeratorsent = 1 if L1=="a university in America"
replace enumeratorsent = 1 if L1=="academic research team"
replace enumeratorsent = 1 if L1=="academic study"
replace enumeratorsent = 1 if L1=="an American research university"
replace enumeratorsent = 1 if L1=="an American university" 
replace enumeratorsent = 1 if L1=="an association for research"
replace enumeratorsent = 1 if L1=="an institute"
replace enumeratorsent = 1 if L1=="an institute for research"
replace enumeratorsent = 1 if L1=="an institute for studies"
replace enumeratorsent = 1 if L1=="an organization Harvard"
replace enumeratorsent = 1 if L1=="an organization doing social research"
replace enumeratorsent = 1 if L1=="an organization doing studies"
replace enumeratorsent = 1 if L1=="an organization or center"
replace enumeratorsent = 1 if L1=="an organization or university"
replace enumeratorsent = 1 if L1=="association for research"
replace enumeratorsent = 1 if L1=="authority from a competent university"
replace enumeratorsent = 1 if L1=="field research studies"
replace enumeratorsent = 1 if L1=="general study"
replace enumeratorsent = 1 if L1=="reearchers from neighboring countries"
replace enumeratorsent = 1 if L1=="research"
replace enumeratorsent = 1 if L1=="research and studies"
replace enumeratorsent = 1 if L1=="research committee"
replace enumeratorsent = 1 if L1=="research company"
replace enumeratorsent = 1 if L1=="research institution"
replace enumeratorsent = 1 if L1=="research institution Proximity" 
replace enumeratorsent = 1 if L1=="research organization"
replace enumeratorsent = 1 if L1=="research specialists"
replace enumeratorsent = 1 if L1=="research university"
replace enumeratorsent = 1 if L1=="researchers"
replace enumeratorsent = 1 if L1=="researchers and studies"
replace enumeratorsent = 1 if L1=="researchers from America"
replace enumeratorsent = 1 if L1=="researchers from an NGO"
replace enumeratorsent = 1 if L1=="survey study"
replace enumeratorsent = 1 if L1=="the American University"
replace enumeratorsent = 1 if L1=="the Turkish University"
replace enumeratorsent = 1 if L1=="the research organization Proximity"
replace enumeratorsent = 1 if L1=="the team"
replace enumeratorsent = 1 if L1=="think tank"
replace enumeratorsent = 1 if L1=="universities"
replace enumeratorsent = 1 if L1=="university"
replace enumeratorsent = 1 if L1=="university research"
replace enumeratorsent = 1 if L1=="university studies"
replace enumeratorsent = 1 if L1=="university study"
replace enumeratorsent = 1 if L1=="volunteer"
replace enumeratorsent = 1 if L1=="volunteers"
replace enumeratorsent = 1 if L1=="Harvard, according to what you told me"
replace enumeratorsent = 1 if L1=="an organization working on research with European universities"
replace enumeratorsent = 1 if L1=="research institutions with Harvard and Yale"
replace enumeratorsent = 1 if L1=="an organization ????????? ???? ??? ???? ?Harvard and Yale"
replace enumeratorsent = 1 if L1=="Harvard and Yale ???? ????? ???????"
replace enumeratorsent = 1 if L1=="a research organization with Harvard and Yale"
replace enumeratorsent = 1 if L1=="Proximity, according to what researcher Ahmad previously told us"
replace enumeratorsent = 1 if L1=="universities with a research organization in Turkey"
replace enumeratorsent = 1 if L1=="Harvard and Yale ??? Male ?? ??????"
replace enumeratorsent = 1 if L1=="The American university Harvard for studies"
replace enumeratorsent = 1 if L1=="research institution ???????"
replace enumeratorsent = 1 if L1=="an international organization with Harvard and Yale"

eststo clear
eststo, title("Model 1"): quietly reg worseweek enumeratorsent wealthcap education gender, robust
eststo, title("Model 2"): quietly reg worseyear enumeratorsent wealthcap education gender, robust
eststo, title("Model 3"): quietly reg worsegoods enumeratorsent wealthcap education gender, robust
esttab using enumerator.tex, cells(b(star fmt(3)) se(par fmt(2))) obslast  stats(r2, fmt(3) label(R-sqr)) keep(enumeratorsent wealthcap education gender) label title("Enumerator Beliefs and Reported Violence and Goods Access\label{impactiv}")  replace

*****Table A4 
version 13.1
****weatlh
recode K11_1-K11_13 (-99=.)
gen wealthsum = K11_1 + K11_2 + K11_3 + K11_4 + K11_5 + K11_6 +K11_7 +K11_8 + K11_9 + K11_10 +K11_11 + K11_12 +K11_13

recode K14_1-K14_13 (-99=.)
gen wealthsumnow = K14_1 + K14_2 + K14_3 + K14_4 + K14_5 + K14_6 +K14_7 +K14_8 + K14_9 + K14_10 +K14_11 + K14_12 +K14_13


recode A12-A14 (-99=.)
recode AGA-AGC (-99=.)


gen viol_week=.
replace viol_week=0 if A12>2 | AGA>2
replace viol_week=1 if A12==2 | A12==1 | AGA==1 | AGA==2
replace viol_week=. if AGA==. & A12==.

gen viol_month=.
replace viol_month=0 if A13>2 | AGB>2
replace viol_month=1 if A13==1 | A13==2 |  AGB==1 | AGB==2
replace viol_month=. if A13==. & AGB==.


gen viol_year=.
replace viol_year=0 if A14>2 | AGC>2
replace viol_year=1 if A14==1 | A14==2 | AGC==1 | AGC==2
replace viol_year=. if AGC==. & A14==.

tab A14
tab AGC
tab viol_year

set more off
foreach treat in info_control symp_control opening_control hostile_control symp_info opening_info hostile_info  ////
	opening_hostile symp_hostile opening_symp {
	tabulate K1 `treat' if know_index==0,  chi2 column
	tabulate Country `treat' if know_index==0, chi2 column
	tabulate country_origin `treat' if know_index==0, chi2 column
	tabulate skill `treat' if know_index==0, chi2 column
	ttest age if know_index==0, by(`treat') unequal
	ttest religiosity if know_index==0, by(`treat') unequal
	ttest wealthsum if know_index==0, by(`treat') unequal
	ttest wealthsumnow if know_index==0, by(`treat') unequal
	ttest violence_index if know_index==0, by(`treat') unequal
	ttest viol_week if know_index==0, by(`treat') unequal
	ttest viol_month if know_index==0, by(`treat') unequal
	ttest viol_year if know_index==0, by(`treat') unequal
}

*Output ttests to create Table A4


***Tables A5
*Regressions on treatments
tab wavetreatment, gen(wave_treat)

renvars wave_treat1 wave_treat2 wave_treat3 wave_treat4 wave_treat5 \ control info_treat symp_treat ////
open_treat hostile_treat

tab K1, gen(gender)
tab country_origin, gen(country_org)

recode skill (1=0)
recode skill (2=1)
tab Country, gen(country_interviewb)

renvars gender1 gender2 country_interviewb1 country_interviewb2 country_interviewb3 country_interviewb4   ////
country_org1 country_org2 country_org3 \ men women  Turkey2 Jordan2 Syria2 Iraq2 Syrian Iraqi Other

label var women "Women"
label var Turkey2 "Interviewed in Turkey"
label var Jordan2 "Interviewed in Jordan" 
label var Syria2 "Interviewed in Syria"
label var Iraq2 "Interviewed in Iraq"
label var Syrian "Syrian"
label var Iraqi "Iraqi"
label var info_treat "Information"
label var symp_treat "Sympathetic"
label var open_treat "Open" 
label var hostile_treat "Hostile"
label var skill "Some College +"
label var age "Age"
label var religiosity "Religiosity"
label var wealthsum "Wealth at home"
label var wealthsumnow "Wealth Now"
label var violence_index "Violence Index"
label var viol_week "Violence (Week Before)"
label var viol_month "Violence (Month Before)"
label var viol_year "Violence (Year Before)"


preserve
set more off
eststo clear
foreach var in control info_treat symp_treat ////
open_treat hostile_treat {
	eststo: logit `var' women Jordan2 Syria2 Iraq2 Iraqi skill age religiosity wealthsum violence_index ////
		viol_week viol_month viol_year if know_index==0, vce(robust)
	eststo: logit `var' women Jordan2 Syria2 Iraq2 Iraqi skill age religiosity wealthsum wealthsumnow violence_index ////
		viol_week viol_month viol_year if know_index==0, vce(robust)
	eststo: reg `var' women Jordan2 Syria2 Iraq2 Iraqi skill age religiosity wealthsum violence_index ////
		viol_week viol_month viol_year if know_index==0, vce(robust)
	eststo: reg `var' women Jordan2 Syria2 Iraq2 Iraqi skill age religiosity wealthsum wealthsumnow violence_index ////
		viol_week viol_month viol_year if know_index==0, vce(robust)
}
esttab using Table_A5_balance_lowknow.tex, label b(2) se(2)  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
title(Effect of Covariates on Treatment Received (Low Knowledge Sample)\label{tab:balancelogits}) ///
mtitles("Control" "Control" "Control" "Control" "Information" "Information" "Information" "Information" ////
"Sympathetic" "Sympathetic" "Sympathetic" "Sympathetic" "Open" "Open" "Open" "Open"  "Hostile" ////
"Hostile" "Hostile" "Hostile") booktabs  ///
nogaps r2(2) scalars(p F) replace 
restore


***Note: Tables A6-A9 & A11 produced in R

**** Table A12
preserve
set more off
eststo clear
foreach var in violence goods turkey trust F6 F8 F15 F11 F12 F13 F3 F4 F5 F7 F14 {
eststo: reg `var' info_treat symp_treat open_treat hostile_treat women Jordan2 Syria2 ////
		Iraq2 Iraqi skill age religiosity wealthsum wealthsumnow violence_index ////
		viol_week viol_month viol_year if know_index==0, vce(robust)
}
esttab using Table_A12_experimental_individualqs_lowknow_july2019.tex, label b(2) se(2)  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
title(Effect of Treatments and Covariates on Experimental Outcomes for Low Knowledge Respondents\label{tab:experresults}) ///
mtitles("Violence" "Goods Access" "Sit. in Turkey" "Trust" "Deportation" "Turn back" "Returned to Turkey" ////
	"EU 1 month" "EU 3 months" "EU 6 months" "Stay permanently" "Stay thru conflict" "Bring family" "Work permit" "Receive Asylum" ////
   ) booktabs nogaps r2(2) replace 
restore

*** Figure A1: Internet Searches for Asylum in Syria, Iraq, and Afghanistan, 2012-17
** use asylumacrosscountry.dta
graph twoway tsline syria iraq afghanistan, tlabel(19231 "9/12" 19910 "Merkel 6/14" 20337 "Merkel 8/15" 21051 "9/17") lcolor (black gray black) lstyle(solid solid dot)  xtitle("Time") ytitle("Relative Interest in Asylum")ylab(0(20)100, nogrid) graphregion(fcolor(white)) plotregion(fcolor(white)) bgcolor(white)legend(rows(1))

*** Figure A2: Internet Searches for Asylum in Syria, Iran, and Kosovo, 2012-17
graph twoway tsline iran kosovo syria , tlabel(19231 "9/12" 19910 "Merkel 6/14" 20337 "Merkel 8/15"  21051 "9/17") lcolor (black gray black) lstyle(solid solid dot) xtitle("Time") ytitle("Relative Interest in Asylum")ylab(0(20)100, nogrid) graphregion(fcolor(white)) plotregion(fcolor(white)) bgcolor(white)legend(rows(1))

   
   
